﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using XFControls.Utils;
using XFControls.XFPanels.XFPanelItems;
using XFControls;
using System.Drawing;
using XFControls.XFPanels;

namespace XFSenseUI.XFItems.SenseControls
{
    public enum ThreeStageToggleStages
    {
        On,
        Middle,
        Off
    }

    public class SenseControlThreeStageToggle : SenseControl
    {
        private int _height;

        public ThreeStageToggleStages Stage { get; set; }

        public SenseControlThreeStageToggle()
        {
            ItemRectangle = new Rectangle();
            _height = -1;
            ItemType = XFItemType.Clickable;
        }

        public override int GetHeight()
        {
            if (_height > -1)
                return _height;

            ItemRectangle = this.GetImageRec("toggle-on");
            _height = ItemRectangle.Height;
            return _height;
        }

        public override void ResetHeight()
        {
            _height = -1;
        }

        public override void ItemPaint(System.Drawing.Graphics g, int x, int y)
        {
            string img = "";
            switch (Stage)
            {
                case ThreeStageToggleStages.On:
                    img = "toggle-on";
                    break;
                case ThreeStageToggleStages.Off:
                    img = "toggle-off";
                    break;
                case ThreeStageToggleStages.Middle:
                    img = "toggle-middle";
                    break;
            }
            this.DrawUI(img, g, new Rectangle(x, y, ItemRectangle.Width, ItemRectangle.Height));
        }

        public override XFItemClickResult GetClickResult()
        {
            switch (Stage)
            {
                case ThreeStageToggleStages.On:
                    Stage = ThreeStageToggleStages.Off;
                    break;
                case ThreeStageToggleStages.Off:
                    Stage = ThreeStageToggleStages.Middle;
                    break;
                case ThreeStageToggleStages.Middle:
                    Stage = ThreeStageToggleStages.On;
                    break;
            }

            return XFItemClickResult.Nothing;
        }
    }
}
